package com.xuecheng.comment.controller;


import com.xuecheng.api.comment.CommentApi;
import com.xuecheng.api.comment.model.dto.CommentDTO;
import com.xuecheng.api.comment.model.qo.CommentModel;
import com.xuecheng.api.comment.model.vo.CommentVO;
import com.xuecheng.comment.service.CommentService;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 课程评论功能
 */
@Slf4j
@RestController
public class CommentController implements CommentApi {

    @Autowired
    private CommentService commentService;
    /*
     * 新增评论
     */
    @PostMapping("/comment/create")
    public CommentDTO createComment(@RequestBody CommentVO vo,String username) {
        return null;
    }


//    @PostMapping("list")
//    public PageVO<CommentDTO> list(PageRequestParams params, @Valid @RequestBody CommentConditionModel commentModel) {
//        return commentService.list(params, commentModel);
//    }


    @PostMapping("course-comment/for-course")
    public PageVO<CommentDTO> queryCommentList(PageRequestParams params,  @RequestBody CommentModel commentModel) {
        return null;
    }

    @PostMapping("course-comment/list")
    public PageVO<CommentDTO> queryCourseCommentList(PageRequestParams params, @RequestBody CommentModel commentModel) {
        log.info("参数为：{},{}", params, commentModel);
        PageVO<CommentDTO> pageVO = commentService.queryCourseCommentList(params, commentModel);
        return pageVO;
    }

    @GetMapping("m/course-comment/list-all")
    public PageVO<CommentDTO> queryMCourseCommentList(PageRequestParams params) {
        log.info("请求参数: {}",params);
        return commentService.queryMCourseCommentList(params);
    }

    @PostMapping("m/course-comment/list-all")
    public PageVO<CommentDTO> queryMCourseCommentList2(PageRequestParams params) {
        log.info("请求参数: {}",params);
        params.setPageNo(2L);
        return commentService.queryMCourseCommentList(params);
    }
//    @PostMapping
//    public CommentDTO comment(@Valid @RequestBody CommentDTO commentDTO) {
//        return commentService.addComment(commentDTO);
//    }


    @GetMapping("l/course-statistics/{targetId}")
    public CommentVO statisticsComment(@PathVariable Long targetId) {
        return null;
    }

    @DeleteMapping("m/delete-comment/{commentId}")
    public void deleteComment(@PathVariable Long commentId) {
        commentService.deleteComment(commentId);
    }

    @DeleteMapping("m/delete-comment/batch-del/{request}")
    public void deleteComments(@PathVariable String request) {
        log.info("参数为：{}", request);
        commentService.deleteComments(request);
    }
}



